/* 
 * File: timespan.h
 * Project: QTimeTracker
 * Author: Steve Sindelar, http://stevesindelar.cz
 * Licence: NewBSD licence.
 */
#ifndef TIMESPAN_H
#define TIMESPAN_H

#include <QDateTime>
#include <QTime>
#include "timespandata.h"


namespace Core
{

	/**
	 * Represents time span - amount of time. 
	 *
	 * This class encapsulates two information: start (type of QDateTime) and length (type of TimeSpanData).
	 * Instances of this class 'live' inside objects of type Item.
	 */
	class TimeSpan
	{
	public:
		TimeSpan();
		TimeSpan(const TimeSpan&);

		/**
		 * Starts the span, technically this means that current time is saved.
		 */
		void start();
		/**
		 * Stops the span, technically this means that length is calculated from start time and saved.
		 * Stopped spand cannot be started again.
		 */
		void stop();

		QDateTime getFrom() const;
		void setFrom(QDateTime val);

		/**
		 * This value is calculated from start time and length.
		 */
		QDateTime getTo() const;
		void setTo(QDateTime val);

		/**
		 * When the span is running the length is calculated from to start time,
		 * when it is stopped the saved length is returned.
		 */
		TimeSpanData getLength() const;
		void setLength(int hours, int minutes, int seconds);

		bool isRunning() const;

		QString note;

		/**
		 * Helper method for retrieving Jesus birth date and time.
		 */
		static QDateTime& zeroDate();

	private:
		/**
		 * Helper method for getting the length as QDateTime.
		 */
		QDateTime _getLength() const;

		QDateTime from;
		QDateTime length;
		bool finished;
	};

}

#endif //TIMESPAN_H
